package micro_demo

import (
	"protobuf/handler"
	"protobuf/pb"

	"github.com/sirupsen/logrus"
	"go-micro.dev/v4"
)

// MicroServer micro 服务
// 命令行执行: micro call future[NewService中的micro.Name] Future.GetMinBar[handler/micro_service.go中] '{"instrument": "rb2205"}'
func MicroServer() error {
	// create service
	service := micro.NewService(
		micro.Name("future"),
		micro.Version("latest"),
		micro.Address(":9876"), // 指定端口
	)

	// initialise flags
	service.Init()

	// register handler
	if err := pb.RegisterFutureHandler(service.Server(), &handler.Future{}); err != nil {
		logrus.Fatal(err)
	}

	// run service
	err := service.Run()
	return err
}
